package com.generator.storageManage.stockControl.service.impl;

import com.generator.storageManage.stockControl.dao.IStockControl;
import com.generator.storageManage.stockControl.pojo.KuCun;
import com.generator.storageManage.stockControl.service.IStockControlService;
import com.generator.util.PageModel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StockControlService implements IStockControlService {

    @Autowired
    private IStockControl stockControl;

    public IStockControl getStockControl() {
        return stockControl;
    }

    public void setStockControl(IStockControl stockControl) {
        this.stockControl = stockControl;
    }

    //拿到所有的库存记录
    @Override
    public List<KuCun> getKuCunByCondition(KuCun kuCun) {
        return stockControl.getKuCunByCondition(kuCun);
    }

    //分页
    public PageModel<KuCun> getKuCunByConditionPage(PageModel<KuCun> pageModel,KuCun kuCun){

        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?3:pageModel.getPageSize());
        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());
        List<KuCun> kuCunByCondition = getKuCunByCondition(kuCun);
        PageInfo<KuCun> warehousePageInfo = new PageInfo<KuCun>(kuCunByCondition);

        pageModel.setData(new ArrayList<KuCun>(kuCunByCondition));
        pageModel.setTotalPage(warehousePageInfo.getPages());
        pageModel.setTotalRows(warehousePageInfo.getTotal());
        return pageModel;

    }
}
